package cn.buyclss.backend.controller.shop;

import cn.buyclss.backend.entity.domain.shop.GoodsCategory;
import cn.buyclss.backend.entity.support.RespResult;
import cn.buyclss.backend.entity.vo.shop.GoodsCategoryPageVO;
import cn.buyclss.backend.entity.vo.shop.GoodsCategoryVO;
import cn.buyclss.backend.service.shop.GoodsCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: Cecurio
 * @create: 2019-03-12 0:30
 **/
@RestController
@RequestMapping("/goods/category")
@Api(value = "商品分类", description = "${GoodsCategoryController.description}")
public class GoodsCategoryController {

    @Autowired
    private GoodsCategoryService goodsCategoryService;

    @PostMapping("/page")
    @ApiOperation(value = "分页获取", notes = "分页获取")
    @ApiImplicitParam(paramType = "header", name = "Authorization", required = true)
    @RequiresAuthentication
    public RespResult page(@RequestBody GoodsCategoryPageVO pageVO) {
        return goodsCategoryService.page(pageVO.getPageIndex(), pageVO.getPageSize());
    }


    @GetMapping("/all")
    @ApiOperation(value = "获取所有", notes = "获取所有的商品种类")
    @ApiImplicitParam(paramType = "header", name = "Authorization", required = true)
    @RequiresAuthentication
    public RespResult all() {
        return goodsCategoryService.getAll();
    }

    @PostMapping("/one")
    @ApiOperation(value = "增加商品类型", notes = "修改商品类型")
    @ApiImplicitParam(paramType = "header", name = "Authorization", required = true)
    @RequiresAuthentication
    public RespResult addCategory(@RequestBody GoodsCategoryVO categoryVO) {
        return goodsCategoryService.addOne(categoryVO);
    }

    @PutMapping("/")
    @ApiOperation(value = "修改商品类型", notes = "修改商品类型")
    @ApiParam(name = "deleted", value = "1表示已删除，0表示未删除")  // 用于方法，参数，字段说明
    @ApiImplicitParam(paramType = "header", name = "Authorization", required = true)
    @RequiresAuthentication
    public RespResult updateCategory(@RequestBody GoodsCategoryVO categoryVO) {
        return goodsCategoryService.update(categoryVO);
    }

    @DeleteMapping("/")
    @ApiOperation(value = "删除商品类型", notes = "删除商品类型")
    //@ApiParam(name = "deleted", value = "1表示已删除，0表示未删除")  // 用于方法，参数，字段说明
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "header", name = "Authorization", required = true),
        @ApiImplicitParam(paramType = "query", name = "categoryId", value = "要删除的种类编号", required = true)
    })
    @RequiresAuthentication
    public RespResult deleteCategory(Integer categoryId) {
        return goodsCategoryService.deleteById(categoryId);
    }


}
